import { Map } from 'immutable'
import * as actionTypes from './constants'

const defaultState = Map({
  user: {},
  articleList: [],
  userProfile: {},
  articleDetail: {},
  userOpus: [],
  walls: [],
  classify: [],
  articleByClassify: [],
  friendList: [],
  mineFollow: [],
  followMine: [],
  articleDiscuss: []
})

function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.CHANGE_USER_BASE:
      return state.set('user', action.user)
    case actionTypes.CHANGE_ARTICLE_LIST:
      return state.set('articleList', action.articleList)
    case actionTypes.CHANGE_USER_PROFILE:
      return state.set('userProfile', action.userProfile)
    case actionTypes.CHANGE_ARTICLE_DETAIL:
      return state.set('articleDetail', action.articleDetail)
    case actionTypes.CHANGE_USER_OPUS:
      return state.set('userOpus', action.userOpus)
    case actionTypes.CHANGE_USER_WALLS:
      return state.set('walls', action.walls)
    case actionTypes.CHANGE_ARTICLE_CLASSIFY:
      return state.set('classify', action.classify)
    case actionTypes.CHANGE_ARTICLE_BY_CLASSIFY:
      return state.set('articleByClassify', action.articleByClassify)
    case actionTypes.CHANGE_FRIEND_LIST:
      return state.set('friendList', action.friendList)
    case actionTypes.CHANGE_MINE_FOLLOW_LIST:
      return state.set('mineFollow', action.mineFollow)
    case actionTypes.CHANGE_FOLLOW_MINE_LIST:
      return state.set('followMine', action.followMine)
    case actionTypes.CHANGE_ARTICLE_DISCUSS_LIST:
      return state.set('articleDiscuss', action.articleDiscuss)
    default:
      return state
  }
}

export default reducer
